import { _decorator, color, Color, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
import { TreaIng } from '../entity/TreaIng';
import TreaApi from '../api/TreaApi';
import { EventManager } from '../event/EventManager';
import { nftdata, PurchaseConfig, PurchaseType } from "../settings/const";
import { ShopIng } from '../entity/ShopIng';
import ResManager from '../common/ResManager';
const { ccclass, property } = _decorator;

@ccclass('MallGoods')
export class MallGoods extends Component {
    /**商品图片 */
    @property(Sprite)
    img: Sprite
    /**商品名称 */
    @property(Label)
    title: Label
    /**商品介绍 */
    @property(Label)
    desc: Label
    /**商品购买按钮 */
    @property(Node)
    shopButton: Node
    /**商品按钮价格 */
    @property(Label)
    shopBtnSprice: Label
    @property(Sprite)
    money:Sprite
   
    @property(SpriteFrame)
    goldImg:SpriteFrame
    @property(SpriteFrame)
    diamondImg:SpriteFrame

     /**当前物品信息 */
     shopItem: ShopIng

    start() {
        this.shopButton.on(Node.EventType.TOUCH_END, this.shopBtn, this)
    }

    shopBtn() {
        EventManager.instance.emit(EventManager.EventType.ShopList, this.shopItem)
    }


    async setData(shopItem: ShopIng) {
        console.log(shopItem)
        this.shopItem = shopItem
        this.title.string = this.shopItem.name
        this.desc.string = this.shopItem.descMsg
        this.img.spriteFrame = await this.shopItem.getShopIngImg()
        
        let arr = this.shopItem.price.split(':')
        if(arr[0] == '元宝'){
            this.money.spriteFrame = this.goldImg
        } else {
            this.money.spriteFrame = this.diamondImg
        }

        this.shopBtnSprice.string = arr[1]
    }
}


